package util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

/**
 * @Auther:Liu
 * @Testname:Mybatisutil
 * @Date:2025/3/27 15:26
 */
public class Mybatisutil {
    /**
     * 获取工厂对象
     *
     * @return
     * @throws Exception
     */
    public SqlSession GC() throws Exception {
        //1.读取mybatis配置文件
        InputStream resourceAsStream = Resources.getResourceAsStream("config/config.xml");
        //2.读取sqlSession工厂对象
        SqlSessionFactory build = new SqlSessionFactoryBuilder().build(resourceAsStream);
        //3.通过工厂获取对象
        SqlSession sqlSession = build.openSession();
        return sqlSession;
    }
}
